package thread;

import static java.lang.Thread.sleep;

public class ThreadDemo8 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() ->{
            System.out.println("hello thread");
            //这个线程的最大运行时间是1s
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        System.out.println("start 之前: " + t.isAlive());
        t.start();
        System.out.println("start 之后: " + t.isAlive());
        Thread.sleep(2000);
        //2s之后, 线程t已经结束了
        System.out.println("结束后: " + t.isAlive());
    }
}
